﻿//Copyright (c) Microsoft Corporation. All rights reserved.

using Microsoft.Ted.Wacel.Cache;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Microsoft.Ted.Wacel.TestConsole.PerformanceTests
{
    public class CompressedCircularPerfTest
    {
        public static int Add(Stopwatch watch)
        {
            int count = 200;
            string load = new string('X', 1024);
            CompressedCircularBuffer buffer = new CompressedCircularBuffer("perf_compressed", 1, batchSize: 5);
            watch.Restart();
            for (int i = 0; i < count; i++)
                buffer.Add(load);
            watch.Stop();
            return count;
        }
        public static int AddWithLargeBatch(Stopwatch watch)
        {
            int count = 200000;
            string load = new string('X', 1024);
            CompressedCircularBuffer buffer = new CompressedCircularBuffer("perf_compressed", 1, batchSize: 1000);
            watch.Restart();
            for (int i = 0; i < count; i++)
                buffer.Add(load);
            watch.Stop();
            return count;
        }
        public static int GPSSimulation(Stopwatch watch)
        {
            int count = 200;
            Random rand = new Random();
            string[] loads = new string[count];
            for (int i = 0; i < loads.Length; i++)
                loads[i] = string.Format("$GPGAA,151119.00,{0:####.#####},N,{1:#####.####},W,1,06,03.2,+00125.5,M,,,,*3F",
                    rand.Next(-9000, 9000), rand.Next(-18000, 18000));
            
            CompressedCircularBuffer buffer = new CompressedCircularBuffer("perf_compressed", 5, batchSize: 50);
            watch.Restart();
            for (int i = 0; i < count; i++)
                buffer.Add(loads[i]);
            watch.Stop();
            return count;
        }
    }
}
